mkdir command
mkdir
- Make or Create Directory(ies)
Create the DIRECTORY(ies), if they do not already exist.
Usage: mkdir [OPTION]... DIRECTORY...
To get help related to the mkdir
command use --help
option
$ mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE set file mode (as in chmod), not a=rwx - umask
-p, --parents no error if existing, make parent directories as needed
-v, --verbose print a message for each created directory
-Z set SELinux security context of each created directory
to the default type
--context[=CTX] like -Z, or if CTX is specified then set the SELinux
or SMACK security context to CTX
--help display this help and exit
--version output version information and exit
-
mkdir
- Make directory.username@linux:~$ mkdir newfolder
username@linux:~$ ls
newfolder -
mkdir -p
- The-p
or--parents
flag, adds some powerful functionality to this command in creating multiple levels of directories by creating all parent directories that do not exist.username@linux:~$ mkdir -p way/to/new/directory
If
way
,way/to
, orway/to/new
do not exist,mkdir -p
will create them automatically, ensuring that the final directoryway/to/new/directory
exists.username@linux:~$ mkdir -p /home/user/project/{src,bin,docs}
username@linux:~$ cd /home/user/project
username@linux:~/home/user/project$ ls
bin docs srcThis command would create a
project
directory under/home/user
, and withinproject
, it would createsrc
,bin
, anddocs
directories, all in one go, without throwing an error if any of these directories already exist.